<template>
  <div class="home">
    <h1 class="h1">This is an home page</h1>
    <el-button @click="show">show</el-button>
  </div>
</template>
<script>
export default {
  name: 'HomeView',
  data () {
    return {}
  },
  mounted () {
    this.listenUpdate()
  },
  methods: {
    show () {
      window.ipcRenderer.send('show', 'ipcRenderer --->ipcMain')
    },
    listenUpdate () {
      window.ipcRenderer.send('checkForUpdate')
      window.ipcRenderer.on('message', (event, text, info) => {
        console.log('arguments====', arguments)
        console.log('event,text====', event, text, info)
      })
      window.ipcRenderer.on('downloadProgress', (event, progressObj) => {
        console.log('progressObj===', progressObj)
        this.downloadPercent = progressObj.percent || 0
      })
      window.ipcRenderer.on('isUpdateNow', () => {
        // 下载完成之后提示用户更新程序
        const myNotification = new Notification('更新包下载完成', {
          body: '更新包下载完成，点击通知重启应用更新应用到最新版本！'
        })

        myNotification.onclick = () => {
          console.log('通知被点击')
          window.ipcRenderer.send('isUpdateNow')
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.h1{
  color: $primary-color;
}
</style>
